<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<link rel="icon" href="favicon.ico" type="image/x-icon"/>
        <title>自定义菜单-微信管理-{$site.BACK_NAME}</title>
        <include file="Public:jscss" />
		<js href="__PUBLIC__/js/admin/json2.js"/>
    </head>
    <body>
        <div class="wrap">
            <include file="Public:head" />
            <div class="mainBody">
                <include file="Public:left" />
                <div id="Right">
                    <div class="Item hr">
                        <div class="current">微信自定义菜单</div>
                    </div>
                        <b>重要提示：</b>
                        菜单修改完后，要点击保存才会生效!
                    <table width="100%" border="0" cellpadding="0" cellspacing="0" class="tab">
                        <thead>
                            <tr align="center">
                                <td width="15%">菜单标题 <b title="单击分类隐藏/显示该分类下在子类">[i]</b></td>
                                <td width="20%">动作类型</td>
                                <td width="45%" align="left">相关信息</td>
                                <td width="20%">操作</td>
                            </tr>
                        </thead>
                        <tbody id="tbody">
							<present name="menu">
                            <volist name="menu.button" id="mu" key="i">
							<php>
							if(!isset($mu['type'])){
								$mu['type']='';
							};
							</php>
							<tr class="mu" id="mu_{$i}">
								<td>
									<input type="text" id="mu_name_{$i}" class="input must_input" value="{$mu.name}"/>
								</td>
								<td>
									<select id="mu_type_{$i}" class="type_select">
										<option value="">-弹出二级菜单-</option>
										<option value="click" {:is_selected($mu['type'],'click')}>-点击推事件-</option>
										<option value="view" {:is_selected($mu['type'],'view')}>-跳转URL-</option>
										<option value="scancode_push" {:is_selected($mu['type'],'scancode_push')}>扫码推事件</option>
										<option value="scancode_waitmsg" {:is_selected($mu['type'],'scancode_waitmsg')}>扫描接收信息</option>
										<option value="pic_sysphoto" {:is_selected($mu['type'],'pic_sysphoto')}>系统拍照发图</option>
										<option value="pic_photo_or_album" {:is_selected($mu['type'],'pic_photo_or_album')}>拍照或者相册发图</option>
										<option value="pic_weixin" {:is_selected($mu['type'],'pic_weixin')}>弹出微信相册发图器</option>
										<option value="location_select" {:is_selected($mu['type'],'location_select')}>弹出地理位置选择器</option>
									</select>
								</td>
								<td>
									<switch name="mu.type" >
									<case value="click|scancode_push|scancode_waitmsg|pic_sysphoto|pic_photo_or_album|pic_weixin|location_select">
									菜单键值:<input id="mu_str_{$i}" type="text" class="input must_input" value="{$mu.key}"/></case>
									<case value="view">
									网页链接:<input id="mu_str_{$i}" type="text" class="input must_input" value="{$mu.url}"/></case>
									<default />暂不需要填写其他信息
									</switch>
								</td>
								<td>
									[ <a href="javascript:void(0);" class="mu_up">上移</a> ] 
									[ <a href="javascript:void(0);" class="mu_down">下移</a> ]
									[ <a href="javascript:void(0);" class="mu_del">删除</a> ]
									[ <a href="javascript:void(0);" class="add_sub">二级</a> ]
								</td>
							</tr>
							<present name="mu.sub_button">
							<volist name="mu.sub_button" id="sub" key="j">
							<tr class="sub_{$i}" id="sub_{$i}_{$j}">
								<td>
									&nbsp;--&nbsp;<input type="text" id="sub_name_{$i}_{$j}" class="input must_input" value="{$sub.name}"/>
								</td>
								<td>
									<select id="sub_type_{$i}_{$j}" class="type_select">
										<option value="click" {:is_selected($sub['type'],'click')}>-点击推事件-</option>
										<option value="view" {:is_selected($sub['type'],'view')}>-跳转URL-</option>
										<option value="scancode_push" {:is_selected($sub['type'],'scancode_push')}>扫码推事件</option>
										<option value="scancode_waitmsg" {:is_selected($sub['type'],'scancode_waitmsg')}>扫描接收信息</option>
										<option value="pic_sysphoto" {:is_selected($sub['type'],'pic_sysphoto')}>系统拍照发图</option>
										<option value="pic_photo_or_album" {:is_selected($sub['type'],'pic_photo_or_album')}>拍照或者相册发图</option>
										<option value="pic_weixin" {:is_selected($sub['type'],'pic_weixin')}>弹出微信相册发图器</option>
										<option value="location_select" {:is_selected($sub['type'],'location_select')}>弹出地理位置选择器</option>
									</select>
								</td>
								<td>
									<switch name="sub.type" >
									<case value="click|scancode_push|scancode_waitmsg|pic_sysphoto|pic_photo_or_album|pic_weixin|location_select">
									菜单键值:<input id="sub_str_{$i}_{$j}" type="text" class="input must_input" value="{$sub.key}"/></case>
									<case value="view">
									网页链接:<input id="sub_str_{$i}_{$j}" type="text" class="input must_input" value="{$sub.url}"/></case>
									<default />暂不需要填写其他信息
									</switch>
								</td>
								<td>
									[ <a href="javascript:void(0);" class="sub_up">上移</a> ] 
									[ <a href="javascript:void(0);" class="sub_down">下移</a> ]
									[ <a href="javascript:void(0);" class="sub_del">删除</a> ]
								</td>
							</tr>
							</volist>
							</present>
                            </volist>
							</present>
                        </tbody>
                    </table>
					<div class="commonBtnArea" >
                        <button class="btn add_mu">一级</button>
                        <button class="btn save_mu">保存</button>
                    </div>
                </div>
            </div>
        </div>
        <form action="" method="post" id="opForm">
            <input id="act" type="hidden" name="act" value="post"/>
            <input id="json" type="hidden" name="json" value="" />
        </form>
        <div class="clear"></div>
        <include file="Public:foot" />
    </body>
<script type="text/javascript">
var mu_item = 1000;
var sub_item = 1000;
$(function(){
	//添加一级菜单
    $(".add_mu").click(function(){
		//只能3个以下
		if($(".mu").length >= 3){
			$.jBox.tip('最多只能3个一级菜单', 'info');
			return false;
		}
		mu_item++;
		var html = "<tr class='mu' id='mu_" + mu_item + "'> ";
		html +=	"<td> ";
		html +=	"<input type='text' id='mu_name_" + mu_item + "' class='input must_input' value=''/> ";
		html +=	"</td> ";
		html +=	"<td> ";
		html +=	"<select id='mu_type_" + mu_item + "' class='type_select'> ";
		html +=	"<option value=''>-弹出二级菜单-</option> ";
		html +=	"<option value='click'>-点击推事件-</option> ";
		html +=	"<option value='view'>-跳转URL-</option> ";
		html +=	"<option value='scancode_push'>扫码推事件</option> ";
		html +=	"<option value='scancode_waitmsg'>扫描接收信息</option> ";
		html +=	"<option value='pic_sysphoto'>系统拍照发图</option> ";
		html +=	"<option value='pic_photo_or_album'>拍照或者相册发图</option> ";
		html +=	"<option value='pic_weixin'>弹出微信相册发图器</option> ";
		html +=	"<option value='location_select'>弹出地理位置选择器</option> ";
		html +=	"</select> ";
		html +=	"</td> ";
		html +=	"<td> ";
		html +=	"暂不需要填写其他信息 ";
		html +=	"</td> ";
		html +=	"<td> ";
		html +=	"[ <a href='javascript:void(0);' class='mu_up'>上移</a> ] ";
		html +=	"[ <a href='javascript:void(0);' class='mu_down'>下移</a> ] ";
		html +=	"[ <a href='javascript:void(0);' class='mu_del'>删除</a> ] ";
		html +=	"[ <a href='javascript:void(0);' class='add_sub'>二级</a> ] ";
		html +=	"</td>";
		html +=	"</tr>";
		$("#tbody").append(html);
	});
	//下拉框选择事件
	$(".type_select").live("change",function(){
		var val = $(this).val();
		var did = $(this).attr("id").replace("type","str");
		var dom = $(this).parent("td").next("td").first();
		switch(val){
		case "click":
		case "scancode_push":
		case "scancode_waitmsg":
		case "pic_sysphoto":
		case "pic_photo_or_album":
		case "pic_weixin":
		case "location_select":
			dom.html("菜单键值:<input id='" + did + "' type='text' class='input must_input'/>");
			break;
		case "view":
			dom.html("网页链接:<input id='" + did + "' type='text' class='input must_input'/>");
			break;
		default:
			dom.html("暂不需要填写其他信息");
		}
	});
	//添加二级菜单
	$(".add_sub").live("click",function(){
		var mu_id = $(this).parents("tr").first().attr("id").replace("mu_","");
		//只能5个以下
		if($(".sub_" + mu_id).length >= 5){
			$.jBox.tip('最多只能5个二级菜单', 'info');
			return false;
		}
		sub_item++;
		var html = "<tr class='sub_" + mu_id + "' id='sub_" + mu_id + "_" + sub_item + "'> ";
		html +=	"<td> ";
		html +=	"&nbsp;--&nbsp;<input type='text' id='sub_name_" + mu_id + "_" + sub_item + "' class='input must_input' value=''/> ";
		html +=	"</td> ";
		html +=	"<td> ";
		html +=	"<select id='sub_type_" + mu_id + "_" + sub_item + "' class='type_select'> ";
		html +=	"<option value='click'>-点击推事件-</option> ";
		html +=	"<option value='view'>-跳转URL-</option> ";
		html +=	"<option value='scancode_push'>扫码推事件</option> ";
		html +=	"<option value='scancode_waitmsg'>扫描接收信息</option> ";
		html +=	"<option value='pic_sysphoto'>系统拍照发图</option> ";
		html +=	"<option value='pic_photo_or_album'>拍照或者相册发图</option> ";
		html +=	"<option value='pic_weixin'>弹出微信相册发图器</option> ";
		html +=	"<option value='location_select'>弹出地理位置选择器</option> ";
		html +=	"</select> ";
		html +=	"</td> ";
		html +=	"<td> ";
		html +=	"菜单键值:<input id='sub_str_" + mu_id + "_" + sub_item + "' class='input' type='text must_input'/> ";
		html +=	"</td> ";
		html +=	"<td> ";
		html +=	"[ <a href='javascript:void(0);' class='sub_up'>上移</a> ] ";
		html +=	"[ <a href='javascript:void(0);' class='sub_down'>下移</a> ] ";
		html +=	"[ <a href='javascript:void(0);' class='sub_del'>删除</a> ] ";
		html +=	"</td>";
		html +=	"</tr>";
		if($("#mu_"+mu_id).next(".sub_" + mu_id).length == 0){
			$("#mu_"+mu_id).after(html);
		}else{
			$("#mu_"+mu_id).nextAll(".sub_" + mu_id).last().after(html);
		}
	});
	//一级菜单删除
	$(".mu_del").live("click",function(){
		var d_mu = $(this).parents("tr").first();
		var mu_id = d_mu.attr("id").replace("mu_","");
		//二级菜单个数
		var d_sub = $(".sub_" + mu_id);
		if(d_sub.length > 0){
			$.jBox.confirm(
				"确定要删除一级菜单【<b>"+$("#mu_name_"+mu_id).val()+"</b>】吗？<br/>这将一并删除其下的" + d_sub.length + "个二级菜单!",
				"友情提示",
				function(v, h, f) {
					if (v == true) {
						d_sub.remove();
						d_mu.remove();
					}
				}, 
				{buttons: {'是': true, '否': false}}
			);
		}else{
			d_mu.remove();
		}
	});
	//一级菜单上移
	$(".mu_up").live("click",function(){
		var d_mu = $(this).parents("tr").first();
		var mu_id = d_mu.attr("id").replace("mu_","");
		//二级菜单个数
		var d_sub = $(".sub_" + mu_id);
		//该一级菜单的前一个同级菜单
		var d_bmu = d_mu.prevAll("tr.mu").first();
		if(d_bmu.length == 0){
			$.jBox.tip('到顶啦!', 'info');
			return false;
		}
		d_bmu.before(d_mu);
		d_mu.after(d_sub);
	});
	//一级菜单下移
	$(".mu_down").live("click",function(){
		var d_mu = $(this).parents("tr").first();
		var mu_id = d_mu.attr("id").replace("mu_","");
		//二级菜单个数
		var d_sub = $(".sub_" + mu_id);
		//该一级菜单的后一个同级菜单
		var d_bmu = d_mu.nextAll("tr.mu").first();
		if(d_bmu.length == 0){
			$.jBox.tip('到底啦!', 'info');
			return false;
		}
		//该同级菜单下的最后一个二级菜单
		var d_bsub = $(".sub_" + d_bmu.attr("id").replace("mu_","")).last();
		if(d_bsub.length == 0){
			d_bmu.after(d_mu);
			d_mu.after(d_sub);
		}else{
			d_bsub.after(d_mu);
			d_mu.after(d_sub);
		}
	});
	//二级菜单删除
	$(".sub_del").live("click",function(){
		var d_sub = $(this).parents("tr").first();
		d_sub.remove();
	});
	//二级菜单上移
	$(".sub_up").live("click",function(){
		var d_sub = $(this).parents("tr").first();
		var mu_id = d_sub.attr("class").replace("sub_","");
		//该二级菜单的前一个同级菜单
		var d_bsub = d_sub.prevAll("tr.sub_" + mu_id).first();
		if(d_bsub.length == 0){
			$.jBox.tip('到顶啦!', 'info');
			return false;
		}
		d_bsub.before(d_sub);
	});
	//二级菜单下移
	$(".sub_down").live("click",function(){
		var d_sub = $(this).parents("tr").first();
		var mu_id = d_sub.attr("class").replace("sub_","");
		//该二级菜单的后一个同级菜单
		var d_bsub = d_sub.nextAll("tr.sub_" + mu_id).first();
		if(d_bsub.length == 0){
			$.jBox.tip('到底啦!', 'info');
			return false;
		}
		d_bsub.after(d_sub);
	});
	//保存全部菜单
    $(".save_mu").click(function(){
		var haserr = false;
		var obj = {};
		//当前全部一级菜单
		var mu_obj = new Array();
		var d_mu = $("tr.mu");
		d_mu.each(function(i){
			var mu_id = $(this).attr("id").replace("mu_","");
			var mu_one = {};
			var mu_name = $("#mu_name_" + mu_id).val();
			var mu_type = $("#mu_type_" + mu_id).val();
			mu_one["name"] = mu_name;
			if(mu_type == ""){
				//弹出二级菜单
				var sub_obj = new Array();
				var d_sub = $("tr.sub_" + mu_id);
				if(d_sub.length == 0){
					$.jBox.tip("一级菜单【<b>" + mu_name + "</b>】当前配置下需要添加二级菜单!", 'info');
					haserr = true;
					return false;
				}
				d_sub.each(function(j){
					var sub_tag = $(this).attr("id").replace("sub","");
					var sub_one = {};
					var sub_name = $("#sub_name" + sub_tag).val();
					var sub_type = $("#sub_type" + sub_tag).val();
					var sub_str = $("#sub_str" + sub_tag).val();
					sub_one["name"] = sub_name;
					sub_one["type"] = sub_type;
					switch(sub_type){
					case "click":
					case "scancode_push":
					case "scancode_waitmsg":
					case "pic_sysphoto":
					case "pic_photo_or_album":
					case "pic_weixin":
					case "location_select":
						sub_one["key"] = sub_str;
						break;
					case "view":
						sub_one["url"] = sub_str;
						break;
					default:
					}
					//加入二级菜单
					sub_obj.push(sub_one);
				});
				mu_one["sub_button"] = sub_obj;
			}else{
				//一级响应目录
				mu_one["type"] = mu_type;
				var mu_str = $("#mu_str_" + mu_id).val();
				switch(mu_type){
				case "click":
				case "scancode_push":
				case "scancode_waitmsg":
				case "pic_sysphoto":
				case "pic_photo_or_album":
				case "pic_weixin":
				case "location_select":
					mu_one["key"] = mu_str;
					break;
				case "view":
					mu_one["url"] = mu_str;
					break;
				default:
				}
			}
			mu_obj.push(mu_one);
		});
		if(haserr){
			return false;
		}
		obj["button"] = mu_obj;
		$("#json").val(JSON.stringify(obj));
		commonAjaxSubmit();
	});
});
</script>
</html>